unit NLicensing;

interface
uses Windows, NUtils, NCore;

//-------------------------------------
// External functions
//-------------------------------------
procedure NLicensingGetInfo(var info: TNLibraryInfo);

function  NLicenseObtain(address: String; port: String; products: String): Boolean;
procedure NLicenseRelease(products: String);
function  NLicenseObtainComponents(address: String; port: String; components: String): Boolean;
procedure NLicenseReleaseComponents(components: String);

implementation
//-------------------------------------
// Constants
//-------------------------------------
 const
  dllName = 'NLicensing.dll';
//-------------------------------------
// External imported function
//-------------------------------------
{$ifdef ver210}
function NLicensingGetInfoInternal(var info: TNLibraryInfo): Integer stdcall; external dllName name 'NLicensingGetInfoW';
function NLicenseObtainInternal(address: PChar; port: PChar; products: PChar; var abailable: Integer): Integer stdcall; external dllName name 'NLicenseObtainW';
function NLicenseReleaseInternal(products: PChar): Integer stdcall; external dllName name 'NLicenseReleaseW';
function NLicenseObtainComponentsInternal(address: PChar; port: PChar; components: PChar; var abailable: Integer): Integer stdcall; external dllName name 'NLicenseObtainComponentsW';
function NLicenseReleaseComponentsInternal(components: PChar): Integer stdcall; external dllName name 'NLicenseReleaseComponentsW';

{$else}
function NLicensingGetInfoInternal(var info: TNLibraryInfo): Integer stdcall; external dllName name 'NLicensingGetInfoA';
function NLicenseObtainInternal(address: PChar; port: PChar; products: PChar; var abailable: Integer): Integer stdcall; external dllName name 'NLicenseObtainW';
function NLicenseReleaseInternal(products: PChar): Integer stdcall; external dllName name 'NLicenseReleaseA';
function NLicenseObtainComponentsInternal(address: PChar; port: PChar; components: PChar; var abailable: Integer): Integer stdcall; external dllName name 'NLicenseObtainComponentsA';
function NLicenseReleaseComponentsInternal(components: PChar): Integer stdcall; external dllName name 'NLicenseReleaseComponentsA';
{$endif}
//-------------------------------------
// Implemented functions
//-------------------------------------

procedure NLicensingGetInfo(var info: TNLibraryInfo);
 var res: Integer;
begin
 res := NLicensingGetInfoInternal(info);
 NCheck(res);
end;

function NLicenseObtain(address: String; port: String; products: String): Boolean;
var tmpAddress, tmpPort, tmpProducts : PChar;
    available, res: Integer;
begin
  available := 0;
  tmpAddress := PChar(address);
  tmpPort := PChar(port);
  tmpProducts := PChar(products);
  res := NLicenseObtainInternal(tmpAddress, tmpPort, tmpProducts, available);
  NCheck(res);
  Result := available = 1;
end;

procedure NLicenseRelease(products: String);
 var res: Integer;
     tmpProducts: PChar;
begin
 tmpProducts := PChar(products);
 res := NLicenseReleaseInternal(tmpProducts);
 NCheck(res);
end;

function NLicenseObtainComponents(address: String; port: String; components: String): Boolean;
var tmpAddress, tmpPort, tmpProducts : PChar;
    available, res: Integer;
begin
  available := 0;
  tmpAddress := PChar(address);
  tmpPort := PChar(port);
  tmpProducts := PChar(components);
  res := NLicenseObtainComponentsInternal(tmpAddress, tmpPort, tmpProducts, available);
  NCheck(res);
  Result := available = 1;
end;

procedure NLicenseReleaseComponents(components: String);
 var res: Integer;
     tmpProducts: PChar;
begin
 tmpProducts := PChar(components);
 res := NLicenseReleaseComponentsInternal(tmpProducts);
 NCheck(res);
end;

end.
